package com.huangge1199.codewars;

/**
 * @ClassName CarMileage
 * @Description TODO
 * @Author huangge1199
 * @Date 2021/10/12 16:41
 **/
public class CarMileage {

    public static int isInteresting(int number, int[] awesomePhrases) {
        //Go to town

        if (number < 97) {
            return 0;
        }

        if (number == 98 || number == 99) {
            return 1;
        }

        if (String.valueOf(number).replace("0", "").length() < 2) {
            return 2;
        }

        int temp = number;
        int nu = temp % 10;
        temp /= 10;
        while (temp > 10) {
            if (temp % 10 != nu) {
                break;
            }
            temp /= 10;
        }
        if (temp == nu) {
            return 2;
        }

        for (int awesomePhrase : awesomePhrases) {
            if (number == awesomePhrase) {
                return 2;
            }
            if (number + 1 == awesomePhrase || number + 2 == awesomePhrase) {
                return 1;
            }
        }

        return 0;
    }
}
